using UnityEngine;
using UnityEngine.EventSystems;

public class PlayerGroundState : PlayerState
{
    public PlayerGroundState(Player player, StateMachine stateMachine, string animName) : base(player, stateMachine, animName)
    {
    }

    public override void Enter()
    {
        base.Enter();
    }

    public override void Exit()
    {
        base.Exit();
    }

    public override void Update()
    {
        base.Update();

        if (Input.GetKeyDown(KeyCode.Mouse1) && HasNoSword())
            stateMachine.ChangeState(player.aimSword);

        if (Input.GetKeyDown(KeyCode.Mouse0) && !EventSystem.current.IsPointerOverGameObject())
            stateMachine.ChangeState(player.primaryAttack);

        if (!entity.IsGroundDetected())
            stateMachine.ChangeState(player.airState);

        if (Input.GetKeyDown(KeyCode.Space) && player.jumpIndex!= 2)
        {
            stateMachine.ChangeState(player.jumpState);
        }

        if (Input.GetKeyDown(KeyCode.Q))
        {
            stateMachine.ChangeState(player.counterAttack);
        }

        if (Input.GetKeyDown(KeyCode.E) && player.skill.blackHole.CanUseSkill())
        {
            stateMachine.ChangeState(player.blackHole);
        }

    }



    bool HasNoSword()
    {
        if (!player.sword) return true;
        player.sword.GetComponent<SwordController>().ReturnSword();
        return false;
    }
}
